#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std; 

struct race_t {
	int start, end; 
}; 

bool cmp(race_t &a, race_t &b)
{
	return a.end==b.end ? (a.start<b.start) : (a.end<b.end); 
}

int main()
{
	vector<race_t> a; 
	unsigned n, i, r=0; 
	int end; 
	
	//freopen("p1803.in", "r", stdin); 
	cin>>n; 
	a.resize(n); 
	for (i=0; i<n; i++) {
		cin>>a[i].start>>a[i].end; 
	}
	sort(a.begin(), a.end(), cmp); 
	
	r = 0; 
	i = 0; 
	end = 0; 
	while(i<n) {
		if (a[i].start>=end) {
			end = a[i].end; 
			r++; 
			i++; 
		} else {
			i++; 
		}
	}
	cout<<r<<endl; 
	return 0; 
}



